package com.wsd.bookkeeping.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wsd.bookkeeping.entity.Record;
import com.wsd.bookkeeping.service.BillingService;
import com.wsd.bookkeeping.service.RecordService;
import com.wsd.common.entity.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 账单
 */
@RestController
@RequestMapping("/bill")
public class BillingController {

    @Resource
    private BillingService billingService;

    @Resource
    private RecordService recordService;

    @GetMapping("/list/{bookId}/{year}")
    public ResponseEntity getBillListByDate(@PathVariable Integer bookId, @PathVariable String year) {
        return ResponseEntity.success().put("list", billingService.queryBillingListByDate(bookId, year));
    }

    @GetMapping("/list/{bookId}/month/{date}")
    public ResponseEntity getBillListByMonthDate(@PathVariable Integer bookId, @PathVariable String date) throws InterruptedException {
        if (bookId > 0 && date != null && date.length() != 6) return ResponseEntity.error();
        Map<String, Object> billListByMonthDate = billingService.getBillListByMonthDate(bookId, date);
        return ResponseEntity.success().put("calculated", billListByMonthDate);
    }

}
